/**
 * Created by kangdaye on 16/6/5.
 */
app.controller('goodsListCtr',["$scope","$rootScope","ngDialog","confirm","message","goodsListCache","goodsListService", function($scope,$rootScope,ngDialog,confirm,message,goodsListCache,goodsListService) {
    $scope.getData = {
        shelves : undefined,  //不传代表全部,1销量2下架
        query : '',
        pageNo:1,
        pageSize:18
    };
    $scope.tab = goodsListCache.listTab;
    $scope.gridOptions = {
        url          : servicePath + 'goods/list',
        columnDefs   : goodsListCache.listTableHeader,
        params       : $scope.getData,
        selectAll    : true
    };

    $scope.searchClick = function(){
        $scope.gridOptions.search();
    };
    
    $scope.tabClick = function(id){
        $scope.getData.shelves = id;
        $scope.gridOptions.refresh();
    };

    $scope.batShelves = function(shelvesBoln,id){
        var selectIds = angular.add($scope.gridOptions.selectData,'id');
        goodsListService.shelves({
            ids : id || selectIds.toString(),
            shelves : shelvesBoln
        },function(){
            $scope.gridOptions.refresh();
            message({text : shelvesBoln ? '上架成功' : '下架成功'});
        });
    };

    $scope.batDetele = function(id){
        confirm({
            scope:$scope,
            text:'确定要删除吗？',
            option:{
                go:function(){
                    var selectIds = angular.add($scope.gridOptions.selectData,'id');
                    goodsListService.delete({
                        ids : id || selectIds.toString()
                    },function(){
                        $scope.gridOptions.refresh();
                        message({text : '删除成功'});
                    });
                }
            }
        });
    };
}]);
